package win007

import (
	
	_ "github.com/go-sql-driver/mysql"
 	"github.com/go-xorm/xorm"
 	"fmt"
)


var engine *xorm.Engine


//初始化数据库
func InitDb(){
	var err error
	engine,err = xorm.NewEngine("mysql","root:@/go2015?charset=utf8")
	if err != nil{
		fmt.Println(err)
		return
	}
	defer engine.Close()
	engine.ShowSQL = true
	err = engine.Sync2(new(Win007NbaLeague),new(Win007NbaTeam))

	

	if err != nil{
		fmt.Println(err)
		return
	}
}

func CreateLeague(zh,tw string) bool{
	var err error
	engine,err = xorm.NewEngine("mysql","root:@/go2015?charset=utf8")
	if err != nil{
		fmt.Println(err)
		return false
	}
	defer engine.Close()
	league := new(Win007NbaLeague)
	league.Zh = zh
	league.Tw = tw
	affected,err := engine.Insert(league)
	if(err != nil){
		fmt.Println(err)
		return false
	}
	if affected > 0 {
		return true
	}else{
		return false
	}
}